package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.PickLabourEntity;
import com.sgb.kjwl.view.ui.activity.pick.PickProjectActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PickLabourAdapter extends BaseRecycleAdapter<PickLabourEntity> {
    private TextView projectInfoView;
    private TextView mTvQuoteImmediately;
    private IOffer iOffer;
    public PickLabourAdapter(Context context, List<PickLabourEntity> datas) {
        super(context, R.layout.item_pick_labour, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PickLabourEntity data) {
        holder.setBinding(BR.viewModel, data);
        projectInfoView = holder.getItem().findViewById(R.id.project_info_view);
        mTvQuoteImmediately = holder.getItem().findViewById(R.id.tv_quote_immediately);
        projectInfoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PickProjectActivity.start(context, data.getProjNo());
            }
        });
        if(data.getProjectStatus() == 0){
            if("1".equals(data.getOfferButtonStr())){
                mTvQuoteImmediately.setText("再次报价");
            }
            mTvQuoteImmediately.setOnClickListener(view -> {
                iOffer.checkLogin(data,layoutId);
            });
        }else {
            mTvQuoteImmediately.setText("项目结束");
            mTvQuoteImmediately.setClickable(false);
            mTvQuoteImmediately.setBackground(context.getResources().getDrawable(R.drawable.square_gray_bg));
            mTvQuoteImmediately.setTextColor(context.getResources().getColor(R.color.colorAccent));mTvQuoteImmediately.setText("再次报价");
        }
    }

    public interface IOffer{
        void checkLogin(PickLabourEntity entity, int id);
    }

    public void IOffer(IOffer iOffer){
        this.iOffer = iOffer;
    }
}
